<?
session_start();
//include('header.php');
require_once('classes/class.jira.php');
$_SESSION['first_log'] = 1;
include('config.php');
ini_set('display_errors', 'Off');
unset($_SESSION['first_log']);
if(isset($_POST["Jusername"]) && isset($_POST["Jpass"]))    
    {
	$_SESSION["Juname"]=$_POST["Jusername"];
	$_SESSION["Jpass"]=$_POST["Jpass"];
	$_SESSION['jiraUserFullName'] = '';
    
    
            
		$config->username= $_POST["Jusername"];
		$config->password= $_POST["Jpass"];
		$config->port= "";
		$config->host= $host;
		$query = $_POST["Jusername"];
		
		$queryIssue = new Jira($config);
		$array=$queryIssue->queryUserGroup($query);
		$response = json_decode($array->responseBody);
		$user="a";
		for($i=0;$i<count($response->groups->items);$i++){
			if($response->groups->items[$i]->name == $authgroup){
                            $user=$_POST["Jusername"];
                            $_SESSION['jiraUserFullName'] = $response->displayName;
			}
		}
		if($user=="a"){
			//echo "<script>alert('Invalid Username or Password');</script>";
                        header('Location:index.php');
		 }
		else{
			//echo '<meta http-equiv="refresh" content="0.1;url=home.php">';
                    $_SESSION['first_log'] = 1;
                    header('Location:home.php');
           
		}
    }
?>